package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;

import com.airline.beans.Customer;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.LoginForm;

public class CustomerLoginAction extends Action {
	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		LoginForm customerForm = (LoginForm) form;
		

		String username = customerForm.getUsername();
		String pwd = customerForm.getPassword();
		Customer cust =proxy.customerLogin(username, pwd);
		

		if (null == cust) {
			customerForm.setError("Username or Password entered is wrong");
			return mapping.findForward("failure");
		}
		HttpSession httpsess = request.getSession();
		httpsess.setAttribute("customer", cust);
		
		
		return mapping.findForward("success");
	}

}
